<?php
define('THEME_URL', get_template_directory_uri());

/*
 * Multi Image Metabox
 */
add_filter('images_cpt','my_image_cpt');
function my_image_cpt(){
    $cpts = array('product');
    return $cpts;
}
add_filter('list_images','my_list_images');
function my_list_images(){

    $picts = array(
        'image1' => '_image1',
        'image2' => '_image2',
        'image3' => '_image3',
        'image4' => '_image4',
        'image5' => '_image5',
    );
    return $picts;
}

/*
 * Fillter Search
 */

//function searchfilter($query) {
//
//    if ($query->is_search && !is_admin() ) {
//        $query->set('post_type',array('product'));
//    }
//    return $query;
//}
//add_filter('pre_get_posts','searchfilter');

//function __search_by_title_only( $search, &$wp_query )
//{
//    global $wpdb;
//    if ( empty( $search ) )
//        return $search; // skip processing - no search term in query
//    $q = $wp_query->query_vars;
//    $n = ! empty( $q['exact'] ) ? '' : '%';
//    $search =
//    $searchand = '';
//    foreach ( (array) $q['search_terms'] as $term ) {
//        $term = esc_sql( like_escape( $term ) );
//        $search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
//        $searchand = ' AND ';
//    }
//    if ( ! empty( $search ) ) {
//        $search = " AND ({$search}) ";
//        if ( ! is_user_logged_in() )
//            $search .= " AND ($wpdb->posts.post_password = '') ";
//    }
//    return $search;
//}
//add_filter( 'posts_search', '__search_by_title_only', 500, 2 );


/*
 *  Add image size
 */
function azio_theme_setup()
{
    add_theme_support('post-thumbnails');
    add_image_size('avatar', 100, 100, true); // 1x1
    add_image_size('featured-image', 460, 345, true); // 4x3
}

add_action('after_setup_theme', 'azio_theme_setup');


/*
 * Script & Style
 */
function azio_scripts_styles()
{
    $version = '19102013_0830';

    // enqueue style
    wp_enqueue_style('az-reset', THEME_URL . '/css/reset.css', array(), $version, 'screen');
    // wp_enqueue_style( 'az-text', THEME_URL .'/css/text.css', array('az-reset'), $version, 'screen');
    wp_enqueue_style('az-style-theme', THEME_URL . '/style.css', array('az-reset'), $version);

    // enqueue script
    wp_enqueue_script('az-js-custom', THEME_URL . '/js/custom.js', array('jquery'), $version, true);


    // Load JS Ajax
    wp_enqueue_script('azio-ajax-handle', THEME_URL . '/js/azio-ajax.js', array('jquery'), $version, true);
    wp_localize_script('azio-ajax-handle', 'azio_ajax', array('ajaxurl' => admin_url('admin-ajax.php')));

}

add_action('wp_enqueue_scripts', 'azio_scripts_styles');

